package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TPurchaser;
import com.ruoyi.system.service.ITPurchaserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购商信息Controller
 * 
 * @author ruoyi
 * @date 2024-05-22
 */
@RestController
@RequestMapping("/system/purchaser")
public class TPurchaserController extends BaseController
{
    @Autowired
    private ITPurchaserService tPurchaserService;

    /**
     * 查询采购商信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TPurchaser tPurchaser)
    {
        startPage();
        List<TPurchaser> list = tPurchaserService.selectTPurchaserList(tPurchaser);
        return getDataTable(list);
    }

    /**
     * 导出采购商信息列表
     */
    @Log(title = "采购商信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPurchaser tPurchaser)
    {
        List<TPurchaser> list = tPurchaserService.selectTPurchaserList(tPurchaser);
        ExcelUtil<TPurchaser> util = new ExcelUtil<TPurchaser>(TPurchaser.class);
        util.exportExcel(response, list, "采购商信息数据");
    }

    /**
     * 获取采购商信息详细信息
     */
    @GetMapping(value = "/{purchaserId}")
    public AjaxResult getInfo(@PathVariable("purchaserId") Long purchaserId)
    {
        return success(tPurchaserService.selectTPurchaserByPurchaserId(purchaserId));
    }

    /**
     * 新增采购商信息
     */
    @Log(title = "采购商信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPurchaser tPurchaser)
    {
        return toAjax(tPurchaserService.insertTPurchaser(tPurchaser));
    }

    /**
     * 修改采购商信息
     */
    @Log(title = "采购商信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPurchaser tPurchaser)
    {
        return toAjax(tPurchaserService.updateTPurchaser(tPurchaser));
    }

    /**
     * 删除采购商信息
     */
    @Log(title = "采购商信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{purchaserIds}")
    public AjaxResult remove(@PathVariable Long[] purchaserIds)
    {
        return toAjax(tPurchaserService.deleteTPurchaserByPurchaserIds(purchaserIds));
    }
}
